<!DOCTYPE html>
<html lang=zh>
<head>
  <meta charset="utf-8">
  
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-transform" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no,email=no,adress=no">
  <!-- Color theme for statusbar -->
  <meta name="theme-color" content="#000000" />
  <!-- 强制页面在当前窗口以独立页面显示,防止别人在框架里调用页面 -->
  <meta http-equiv="window-target" content="_top" />
  
  
  <title>Docker 已创建容器挂载目录 | 知识是最有价值的东西</title>
  <meta name="description" content="Docker 已创建容器挂载目录 Docker 已创建容器挂载目录的三种方式  方式一：修改配置文件（需停止docker服务）1、停止docker服务 systemctl stop docker.service（关键，修改之前必须停止docker服务） 2、修改配置文件中的目录位置 vim &#x2F;var&#x2F;lib&#x2F;docker&#x2F;containers&#x2F;container-ID&#x2F;config.v2.json">
<meta property="og:type" content="article">
<meta property="og:title" content="Docker 已创建容器挂载目录">
<meta property="og:url" content="http:&#x2F;&#x2F;jirenyou.gitee.io&#x2F;blog&#x2F;2019&#x2F;12&#x2F;31&#x2F;docker&#x2F;docker-container-volumes-edit&#x2F;index.html">
<meta property="og:site_name" content="知识是最有价值的东西">
<meta property="og:description" content="Docker 已创建容器挂载目录 Docker 已创建容器挂载目录的三种方式  方式一：修改配置文件（需停止docker服务）1、停止docker服务 systemctl stop docker.service（关键，修改之前必须停止docker服务） 2、修改配置文件中的目录位置 vim &#x2F;var&#x2F;lib&#x2F;docker&#x2F;containers&#x2F;container-ID&#x2F;config.v2.json">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2019-12-31T12:40:15.000Z">
<meta property="article:modified_time" content="2019-12-31T12:40:15.000Z">
<meta property="article:author" content="Jirry">
<meta property="article:tag" content="docker">
<meta property="article:tag" content="volumes">
<meta name="twitter:card" content="summary">
  <!-- Canonical links -->
  <link rel="canonical" href="http://jirenyou.gitee.io/blog/2019/12/31/docker/docker-container-volumes-edit/index.html">
  
    <link rel="alternate" href="/atom.xml" title="知识是最有价值的东西" type="application/atom+xml">
  
  
    <link rel="icon" href="/blog/favicon.ico" type="image/x-icon">
  
  
<link rel="stylesheet" href="/blog/css/style.css">

  
  
  
  
<meta name="generator" content="Hexo 4.1.0"></head>


<body class="main-center theme-black" itemscope itemtype="http://schema.org/WebPage">
  <header class="header" itemscope itemtype="http://schema.org/WPHeader">
  <div class="slimContent">
    <div class="navbar-header">
      
      
      <div class="profile-block text-center">
        <a id="avatar" href="https://jirenyou.gitee.io/blog" target="_blank">
          <img class="img-circle img-rotate" src="/blog/images/avatar.jpg" width="200" height="200">
        </a>
        <h2 id="name" class="hidden-xs hidden-sm">Jirry</h2>
        <h3 id="title" class="hidden-xs hidden-sm hidden-md">Back end development Architecture</h3>
        <small id="location" class="text-muted hidden-xs hidden-sm"><i class="icon icon-map-marker"></i> Shenzhen, China</small>
      </div>
      
      <div class="search" id="search-form-wrap">

    <form class="search-form sidebar-form">
        <div class="input-group">
            <input type="text" class="search-form-input form-control" placeholder="搜索" />
            <span class="input-group-btn">
                <button type="submit" class="search-form-submit btn btn-flat" onclick="return false;"><i class="icon icon-search"></i></button>
            </span>
        </div>
    </form>
    <div class="ins-search">
  <div class="ins-search-mask"></div>
  <div class="ins-search-container">
    <div class="ins-input-wrapper">
      <input type="text" class="ins-search-input" placeholder="想要查找什么..." x-webkit-speech />
      <button type="button" class="close ins-close ins-selectable" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
    </div>
    <div class="ins-section-wrapper">
      <div class="ins-section-container"></div>
    </div>
  </div>
</div>


</div>
      <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <nav id="main-navbar" class="collapse navbar-collapse" itemscope itemtype="http://schema.org/SiteNavigationElement" role="navigation">
      <ul class="nav navbar-nav main-nav ">
        
        
        <li class="menu-item menu-item-home">
          <a href="/blog/.">
            
            <i class="icon icon-home-fill"></i>
            
            <span class="menu-title">首页</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives">
            
            <i class="icon icon-archives-fill"></i>
            
            <span class="menu-title">归档</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories">
            
            <i class="icon icon-folder"></i>
            
            <span class="menu-title">分类</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags">
            
            <i class="icon icon-tags"></i>
            
            <span class="menu-title">标签</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-repository">
          <a href="/blog/repository">
            
            <i class="icon icon-project"></i>
            
            <span class="menu-title">项目</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-links">
          <a href="/blog/links">
            
            <i class="icon icon-friendship"></i>
            
            <span class="menu-title">友链</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-about">
          <a href="/blog/about">
            
            <i class="icon icon-cup-fill"></i>
            
            <span class="menu-title">关于</span>
          </a>
        </li>
        
      </ul>
      
	
    <ul class="social-links">
    	
        <li><a href="https://github.com/jirryji" target="_blank" title="Github" data-toggle=tooltip data-placement=top><i class="icon icon-github"></i></a></li>
        
        <li><a href="https://weibo.com/7355950025" target="_blank" title="Weibo" data-toggle=tooltip data-placement=top><i class="icon icon-weibo"></i></a></li>
        
        <li><a href="/blog/atom.xml" target="_blank" title="Rss" data-toggle=tooltip data-placement=top><i class="icon icon-rss"></i></a></li>
        
    </ul>

    </nav>
  </div>
</header>

  
    <aside class="sidebar" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    
      <div class="widget">
    <h3 class="widget-title">公告</h3>
    <div class="widget-body">
        <div id="board">
            <div class="content">
                <p>欢迎交流与分享经验!</p>
            </div>
        </div>
    </div>
</div>

    
      
  <div class="widget">
    <h3 class="widget-title">分类</h3>
    <div class="widget-body">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/docker/">docker</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/elasticsearch/">elasticsearch</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/java/">java</a><span class="category-list-count">9</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/php/">php</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/">版本控制</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E8%AF%AD%E6%B3%95/">语法</a><span class="category-list-count">1</span><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E8%AF%AD%E6%B3%95/markdown-%E8%AF%AD%E6%B3%95/">markdown 语法</a><span class="category-list-count">1</span></li></ul></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签</h3>
    <div class="widget-body">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/aop/" rel="tag">aop</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/bloom-filter/" rel="tag">bloom-filter</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/busybox/" rel="tag">busybox</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/docker/" rel="tag">docker</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/elasticsearch/" rel="tag">elasticsearch</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/es/" rel="tag">es</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/filter/" rel="tag">filter</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/git/" rel="tag">git</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/hashMap/" rel="tag">hashMap</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/idea/" rel="tag">idea</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/interceptor/" rel="tag">interceptor</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/iterator/" rel="tag">iterator</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/java/" rel="tag">java</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/localDateTime/" rel="tag">localDateTime</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/map/" rel="tag">map</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/markdown/" rel="tag">markdown</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/maven/" rel="tag">maven</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/redis/" rel="tag">redis</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/redis-lua%E8%84%9A%E6%9C%AC/" rel="tag">redis lua脚本</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/volumes/" rel="tag">volumes</a><span class="tag-list-count">1</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签云</h3>
    <div class="widget-body tagcloud">
      <a href="/blog/tags/aop/" style="font-size: 13px;">aop</a> <a href="/blog/tags/bloom-filter/" style="font-size: 13px;">bloom-filter</a> <a href="/blog/tags/busybox/" style="font-size: 13px;">busybox</a> <a href="/blog/tags/docker/" style="font-size: 14px;">docker</a> <a href="/blog/tags/elasticsearch/" style="font-size: 13.67px;">elasticsearch</a> <a href="/blog/tags/es/" style="font-size: 13px;">es</a> <a href="/blog/tags/filter/" style="font-size: 13.33px;">filter</a> <a href="/blog/tags/git/" style="font-size: 13.33px;">git</a> <a href="/blog/tags/hashMap/" style="font-size: 13px;">hashMap</a> <a href="/blog/tags/idea/" style="font-size: 13px;">idea</a> <a href="/blog/tags/interceptor/" style="font-size: 13px;">interceptor</a> <a href="/blog/tags/iterator/" style="font-size: 13px;">iterator</a> <a href="/blog/tags/java/" style="font-size: 13.67px;">java</a> <a href="/blog/tags/localDateTime/" style="font-size: 13px;">localDateTime</a> <a href="/blog/tags/map/" style="font-size: 13px;">map</a> <a href="/blog/tags/markdown/" style="font-size: 13px;">markdown</a> <a href="/blog/tags/maven/" style="font-size: 13.67px;">maven</a> <a href="/blog/tags/redis/" style="font-size: 13px;">redis</a> <a href="/blog/tags/redis-lua%E8%84%9A%E6%9C%AC/" style="font-size: 13px;">redis lua脚本</a> <a href="/blog/tags/volumes/" style="font-size: 13px;">volumes</a>
    </div>
  </div>

    
      
  <div class="widget">
    <h3 class="widget-title">归档</h3>
    <div class="widget-body">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/01/">一月 2020</a><span class="archive-list-count">9</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2019/12/">十二月 2019</a><span class="archive-list-count">11</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget-body">
      <ul class="recent-post-list list-unstyled no-thumbnail">
        
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/java/">java</a>
              </p>
              <p class="item-title">
                <a href="/blog/2020/01/14/java/maven/mvn-private-repo/" class="title">Maven私服（Nexus）搭建</a>
              </p>
              <p class="item-date">
                <time datetime="2020-01-14T13:37:39.000Z" itemprop="datePublished">2020-01-14</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/java/">java</a>
              </p>
              <p class="item-title">
                <a href="/blog/2020/01/09/java/java-idea-start-slow/" class="title">解决Idea启动Spring Boot很慢的问题</a>
              </p>
              <p class="item-date">
                <time datetime="2020-01-09T15:24:15.000Z" itemprop="datePublished">2020-01-09</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/java/">java</a>
              </p>
              <p class="item-title">
                <a href="/blog/2020/01/09/java/java-springboot-filter-in-aop/" class="title">AOP（面向切面编程）、Filter（过虑器）、Interceptor（拦截器）</a>
              </p>
              <p class="item-date">
                <time datetime="2020-01-09T15:24:15.000Z" itemprop="datePublished">2020-01-09</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/java/">java</a>
              </p>
              <p class="item-title">
                <a href="/blog/2020/01/09/java/java-req-resp/" class="title">HttpServletRequest 与 HttpServletResponse 的实现类</a>
              </p>
              <p class="item-date">
                <time datetime="2020-01-09T08:24:15.000Z" itemprop="datePublished">2020-01-09</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/java/">java</a>
              </p>
              <p class="item-title">
                <a href="/blog/2020/01/09/java/java-springboot-filter/" class="title">Spring Boot 过滤器 Filter</a>
              </p>
              <p class="item-date">
                <time datetime="2020-01-09T08:24:15.000Z" itemprop="datePublished">2020-01-09</time>
              </p>
            </div>
          </li>
          
      </ul>
    </div>
  </div>
  

    
  </div>
</aside>

  
  
<aside class="sidebar sidebar-toc collapse" id="collapseToc" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    <nav id="toc" class="article-toc">
      <h3 class="toc-title">文章目录</h3>
      <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#Docker-已创建容器挂载目录"><span class="toc-number">1.</span> <span class="toc-text">Docker 已创建容器挂载目录</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#方式一：修改配置文件（需停止docker服务）"><span class="toc-number">1.1.</span> <span class="toc-text">方式一：修改配置文件（需停止docker服务）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#方式二：提交现有容器为新镜像，然后重新运行它"><span class="toc-number">1.2.</span> <span class="toc-text">方式二：提交现有容器为新镜像，然后重新运行它</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#方式三：export容器为镜像，然后import为新镜像"><span class="toc-number">1.3.</span> <span class="toc-text">方式三：export容器为镜像，然后import为新镜像</span></a></li></ol></li></ol>
    </nav>
  </div>
</aside>

<main class="main" role="main">
  <div class="content">
  <article id="post-docker/docker-container-volumes-edit" class="article article-type-post" itemscope itemtype="http://schema.org/BlogPosting">
    
    <div class="article-header">
      
        
  
    <h1 class="article-title" itemprop="name">
      Docker 已创建容器挂载目录
    </h1>
  

      
      <div class="article-meta">
        <span class="article-date">
    <i class="icon icon-calendar-check"></i>
	<a href="/blog/2019/12/31/docker/docker-container-volumes-edit/" class="article-date">
	  <time datetime="2019-12-31T12:40:15.000Z" itemprop="datePublished">2019-12-31</time>
	</a>
</span>
        
  <span class="article-category">
    <i class="icon icon-folder"></i>
    <a class="article-category-link" href="/blog/categories/docker/">docker</a>
  </span>

        
  <span class="article-tag">
    <i class="icon icon-tags"></i>
	<a class="article-tag-link" href="/blog/tags/docker/" rel="tag">docker</a>, <a class="article-tag-link" href="/blog/tags/volumes/" rel="tag">volumes</a>
  </span>


        
	<span class="article-read hidden-xs">
	    <i class="icon icon-eye-fill" aria-hidden="true"></i>
	    <span id="busuanzi_container_page_pv">
			<span id="busuanzi_value_page_pv">0</span>
		</span>
	</span>


        <span class="post-comment"><i class="icon icon-comment"></i> <a href="/blog/2019/12/31/docker/docker-container-volumes-edit/#comments" class="article-comment-link">评论</a></span>
        
	
	

      </div>
    </div>
    <div class="article-entry marked-body" itemprop="articleBody">
      
        <h2 id="Docker-已创建容器挂载目录"><a href="#Docker-已创建容器挂载目录" class="headerlink" title="Docker 已创建容器挂载目录"></a>Docker 已创建容器挂载目录</h2><blockquote>
<p>Docker 已创建容器挂载目录的三种方式</p>
</blockquote>
<h3 id="方式一：修改配置文件（需停止docker服务）"><a href="#方式一：修改配置文件（需停止docker服务）" class="headerlink" title="方式一：修改配置文件（需停止docker服务）"></a>方式一：修改配置文件（需停止docker服务）</h3><p><strong>1、停止docker服务</strong></p>
<p>systemctl stop docker.service（关键，修改之前必须停止docker服务）</p>
<p><strong>2、修改配置文件中的目录位置</strong></p>
<p>vim /var/lib/docker/containers/container-ID/config.v2.json</p>
<figure class="highlight json"><table><tr><td class="code"><pre><span class="line">"MountPoints":</span></pre></td></tr><tr><td class="code"><pre><span class="line">&#123;</span></pre></td></tr><tr><td class="code"><pre><span class="line">	<span class="attr">"/home"</span>: &#123;</span></pre></td></tr><tr><td class="code"><pre><span class="line">		<span class="attr">"Source"</span>: <span class="string">"/docker"</span>,</span></pre></td></tr><tr><td class="code"><pre><span class="line">		<span class="attr">"Destination"</span>: <span class="string">"/home"</span>,</span></pre></td></tr><tr><td class="code"><pre><span class="line">		<span class="attr">"RW"</span>: <span class="literal">true</span>,</span></pre></td></tr><tr><td class="code"><pre><span class="line">		<span class="attr">"Name"</span>: <span class="string">""</span>,</span></pre></td></tr><tr><td class="code"><pre><span class="line">		<span class="attr">"Driver"</span>: <span class="string">""</span>,</span></pre></td></tr><tr><td class="code"><pre><span class="line">		<span class="attr">"Type"</span>: <span class="string">"bind"</span>,</span></pre></td></tr><tr><td class="code"><pre><span class="line">		<span class="attr">"Propagation"</span>: <span class="string">"rprivate"</span>,</span></pre></td></tr><tr><td class="code"><pre><span class="line">		<span class="attr">"Spec"</span>: &#123;</span></pre></td></tr><tr><td class="code"><pre><span class="line">			<span class="attr">"Type"</span>: <span class="string">"bind"</span>,</span></pre></td></tr><tr><td class="code"><pre><span class="line">			<span class="attr">"Source"</span>: <span class="string">"//docker/"</span>,</span></pre></td></tr><tr><td class="code"><pre><span class="line">			<span class="attr">"Target"</span>: <span class="string">"/home"</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">		&#125;</span></pre></td></tr><tr><td class="code"><pre><span class="line">	&#125;</span></pre></td></tr><tr><td class="code"><pre><span class="line">&#125;</span></pre></td></tr></table></figure>

<p><strong>3、启动docker服务</strong></p>
<p>systemctl start docker.service</p>
<p><strong>4、启动docker容器</strong></p>
<p>docker start &lt;container-name/ID&gt;</p>
<h3 id="方式二：提交现有容器为新镜像，然后重新运行它"><a href="#方式二：提交现有容器为新镜像，然后重新运行它" class="headerlink" title="方式二：提交现有容器为新镜像，然后重新运行它"></a>方式二：提交现有容器为新镜像，然后重新运行它</h3><p><strong>1、查看容器ID</strong></p>
<p><code>docker container ps -a</code></p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">docker container ps -a</span></pre></td></tr><tr><td class="code"><pre><span class="line">CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES</span></pre></td></tr><tr><td class="code"><pre><span class="line">48dd9d980c56        elasticsearch       <span class="string">"/docker-entrypoint.…"</span>   41 seconds ago      Exited (0) 12 seconds ago                       tmp-es</span></pre></td></tr></table></figure>



<p><strong>2、提交容器到新镜像</strong></p>
<p><code>docker commit [CONTAINER_ID] [IMAGES_NAME:TAG]</code></p>
<ul>
<li>CONTAINER_ID：现有容器ID</li>
<li>IMAGES_NAME：新镜像名称</li>
</ul>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">docker commit 48dd9d980c56 mycentos:1.0</span></pre></td></tr></table></figure>



<p><strong>3、删除旧容器</strong></p>
<p><code>docker rm [CONTAINER_NAME|CONTAINER_ID]</code></p>
<ul>
<li>CONTAINER_NAME：容器名称</li>
<li>CONTAINER_ID：容器ID</li>
</ul>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">docker rm MyCentOS</span></pre></td></tr></table></figure>



<p><strong>4、从提交的新镜像运行一个新容器</strong></p>
<p><code>docker run -it --name [CONTAINER_NAME] -v [HOST_PATH_DIR]:[CONTAINER_PATH_DIR] [IMAGES_NAME] [CMD]</code></p>
<ul>
<li>CONTAINER_NAME：容器名称</li>
<li>HOST_PATH_DIR：宿主机绝对路径</li>
<li>CONTAINER_PATH_DIR：容器绝对路径</li>
<li>IMAGES_NAME：镜像名称</li>
<li>CMD：运行命令</li>
</ul>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">docker run -it --name MyCentOS -v /var/www:/var/www mycentos:1.0 /bin/bash</span></pre></td></tr></table></figure>



<h3 id="方式三：export容器为镜像，然后import为新镜像"><a href="#方式三：export容器为镜像，然后import为新镜像" class="headerlink" title="方式三：export容器为镜像，然后import为新镜像"></a>方式三：export容器为镜像，然后import为新镜像</h3><p><strong>1、导出容器到镜像</strong></p>
<p><code>docker export [CONTAINER_NAME|CONTAINER_ID] &gt; [PATH_FILE]</code></p>
<ul>
<li>CONTAINER_NAME：容器名称</li>
<li>CONTAINER_ID：容器ID</li>
<li>PATH_FILE：导出镜像路径及名称</li>
</ul>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">docker <span class="built_in">export</span> MyCentOS &gt; /home/data/mycentos.tar.gz</span></pre></td></tr></table></figure>



<p><strong>2、导入镜像</strong></p>
<p><code>docker import [PATH_FILE] [IMAGES_NAME:TAG]</code></p>
<ul>
<li>PATH_FILE：镜像文件路径</li>
<li>IMAGES_NAME：新镜像名称</li>
<li>TAG：新镜像标签</li>
</ul>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">docker import /home/data/mycentos.tar.gz mycentos:1.0</span></pre></td></tr></table></figure>



<p><strong>3、删除旧容器</strong></p>
<p><code>docker rm [CONTAINER_NAME|CONTAINER_ID]</code></p>
<ul>
<li>CONTAINER_NAME：容器名称</li>
<li>CONTAINER_ID：容器ID</li>
</ul>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">docker rm MyCentOS</span></pre></td></tr></table></figure>



<p><strong>4、从新镜像运行一个新容器</strong></p>
<p><code>docker run -it --name [CONTAINER_NAME] -v [HOST_PATH_DIR]:[CONTAINER_PATH_DIR] [IMAGES_NAME] [CMD]</code></p>
<ul>
<li>CONTAINER_NAME：容器名称</li>
<li>HOST_PATH_DIR：宿主机绝对路径</li>
<li>CONTAINER_PATH_DIR：容器绝对路径</li>
<li>IMAGES_NAME：镜像名称</li>
<li>CMD：运行命令</li>
</ul>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">docker run -it --name MyCentOS -v /var/www:/var/www mycentos:1.0 /bin/bash</span></pre></td></tr></table></figure>
      
    </div>
    <div class="article-footer">
      <blockquote class="mt-2x">
  <ul class="post-copyright list-unstyled">
    
    <li class="post-copyright-link hidden-xs">
      <strong>本文链接：</strong>
      <a href="http://jirenyou.gitee.io/blog/2019/12/31/docker/docker-container-volumes-edit/" title="Docker 已创建容器挂载目录" target="_blank" rel="external">http://jirenyou.gitee.io/blog/2019/12/31/docker/docker-container-volumes-edit/</a>
    </li>
    
    <li class="post-copyright-license">
      <strong>版权声明： </strong> 本博客所有文章除特别声明外，均采用 <a href="http://creativecommons.org/licenses/by/4.0/deed.zh" target="_blank" rel="external">CC BY 4.0 CN协议</a> 许可协议。转载请注明出处！
    </li>
  </ul>
</blockquote>


<div class="panel panel-default panel-badger">
  <div class="panel-body">
    <figure class="media">
      <div class="media-left">
        <a href="https://jirenyou.gitee.io/blog" target="_blank" class="img-burn thumb-sm visible-lg">
          <img src="/blog/images/avatar.jpg" class="img-rounded w-full" alt="">
        </a>
      </div>
      <div class="media-body">
        <h3 class="media-heading"><a href="https://jirenyou.gitee.io/blog" target="_blank"><span class="text-dark">Jirry</span><small class="ml-1x">Back end development Architecture</small></a></h3>
        <div>后端开发攻城狮，热爱互联网技术，爱学习，勤思考！</div>
      </div>
    </figure>
  </div>
</div>


    </div>
  </article>
  
    
  <section id="comments">
  	
      <div id="vcomments"></div>
    
  </section>


  
</div>

  <nav class="bar bar-footer clearfix" data-stick-bottom>
  <div class="bar-inner">
  
  <ul class="pager pull-left">
    
    <li class="prev">
      <a href="/blog/2020/01/02/elasticsearch/es-rest-api/" title="ElasticSearch RestFul API接口"><i class="icon icon-angle-left" aria-hidden="true"></i><span>&nbsp;&nbsp;上一篇</span></a>
    </li>
    
    
    <li class="next">
      <a href="/blog/2019/12/30/docker/docker-es/" title="Docker 安装 ElasticSearch(ES)"><span>下一篇&nbsp;&nbsp;</span><i class="icon icon-angle-right" aria-hidden="true"></i></a>
    </li>
    
    
    <li class="toggle-toc">
      <a class="toggle-btn collapsed" data-toggle="collapse" href="#collapseToc" aria-expanded="false" title="文章目录" role="button">
        <span>[&nbsp;</span><span>文章目录</span>
        <i class="text-collapsed icon icon-anchor"></i>
        <i class="text-in icon icon-close"></i>
        <span>]</span>
      </a>
    </li>
    
  </ul>
  
  
  <!-- Button trigger modal -->
  <button type="button" class="btn btn-fancy btn-donate pop-onhover bg-gradient-warning" data-toggle="modal" data-target="#donateModal"><span>赏</span></button>
  <!-- <div class="wave-icon wave-icon-danger btn-donate" data-toggle="modal" data-target="#donateModal">
    <div class="wave-circle"><span class="icon"><i class="icon icon-bill"></i></span></div>
  </div> -->
  
  
  <div class="bar-right">
    
    <div class="share-component" data-sites="weibo,qq,wechat,facebook,twitter" data-mobile-sites="weibo,qq,qzone"></div>
    
  </div>
  </div>
</nav>
  
<!-- Modal -->
<div class="modal modal-center modal-small modal-xs-full fade" id="donateModal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content donate">
      <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
      <div class="modal-body">
        <div class="donate-box">
          <div class="donate-head">
            <p>感谢您的支持，我会继续努力的!</p>
          </div>
          <div class="tab-content">
            <div role="tabpanel" class="tab-pane fade active in" id="alipay">
              <div class="donate-payimg">
                <img src="/blog/images/donate/alipay.jpeg" alt="扫码支持" title="扫一扫" />
              </div>
              <p class="text-muted mv">扫码打赏，你说多少就多少</p>
              <p class="text-grey">打开支付宝扫一扫，即可进行扫码打赏哦</p>
            </div>
            <div role="tabpanel" class="tab-pane fade" id="wechatpay">
              <div class="donate-payimg">
                <img src="/blog/images/donate/wechat.jpeg" alt="扫码支持" title="扫一扫" />
              </div>
              <p class="text-muted mv">扫码打赏，你说多少就多少</p>
              <p class="text-grey">打开微信扫一扫，即可进行扫码打赏哦</p>
            </div>
          </div>
          <div class="donate-footer">
            <ul class="nav nav-tabs nav-justified" role="tablist">
              <li role="presentation" class="active">
                <a href="#alipay" id="alipay-tab" role="tab" data-toggle="tab" aria-controls="alipay" aria-expanded="true"><i class="icon icon-alipay"></i> 支付宝</a>
              </li>
              <li role="presentation" class="">
                <a href="#wechatpay" role="tab" id="wechatpay-tab" data-toggle="tab" aria-controls="wechatpay" aria-expanded="false"><i class="icon icon-wepay"></i> 微信支付</a>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>



</main>

  <footer class="footer" itemscope itemtype="http://schema.org/WPFooter">
	
	
    <ul class="social-links">
    	
        <li><a href="https://github.com/jirryji" target="_blank" title="Github" data-toggle=tooltip data-placement=top><i class="icon icon-github"></i></a></li>
        
        <li><a href="https://weibo.com/7355950025" target="_blank" title="Weibo" data-toggle=tooltip data-placement=top><i class="icon icon-weibo"></i></a></li>
        
        <li><a href="/blog/atom.xml" target="_blank" title="Rss" data-toggle=tooltip data-placement=top><i class="icon icon-rss"></i></a></li>
        
    </ul>

    <div class="copyright">
    	
        &copy; 2020 Jirry
        
        <div class="publishby">
        	Theme by <a href="https://github.com/cofess" target="_blank"> cofess </a>base on <a href="https://github.com/cofess/hexo-theme-pure" target="_blank">pure</a>.
        </div>
    </div>
</footer>
  <script src="//cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<script>
window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
</script>

<script src="/blog/js/plugin.min.js"></script>


<script src="/blog/js/application.js"></script>


    <script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(未命名)',
        },
        ROOT_URL: '/blog/',
        CONTENT_URL: '/blog/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>

<script src="/blog/js/insight.js"></script>






   
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>





   
    
  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/valine"></script>
  <script type="text/javascript">
  var GUEST = ['nick', 'mail', 'link'];
  var meta = 'nick,mail,link';
  meta = meta.split(',').filter(function(item) {
    return GUEST.indexOf(item) > -1;
  });
  new Valine({
    el: '#vcomments',
    verify: false,
    notify: false,
    appId: '',
    appKey: '',
    placeholder: 'Just go go',
    avatar: 'mm',
    meta: meta,
    pageSize: '10' || 10,
    visitor: false
  });
  </script>

     







</body>
</html>